<?php
/**
 * Skyline :: Patterns & component framework
 * Copyright 2010-2011 Ian Unruh (Xerof3ar)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
namespace Skyline\Structure\Sequence;
use Skyline\Structure\CollectionInterface;

/**
 * A list is a sequential container of elements supporting random access
 * 
 * @author Ian Unruh (Xerof3ar) <ianunruh@gmail.com>
 * @since Class avaliable since release 1.0
 */
interface ListInterface extends CollectionInterface
{
	/**
	 * Adds an element to the list at a given index
	 * 
	 * @throws OutOfBoundsException If index is out of bounds (index < 0 || index > count)
	 * @param int $index
	 * @param mixed $element
	 * @return void
	 */
	public function addByIndex($index, $element);
	
	/**
	 * Adds multiple elements to the list at a given index
	 * 
	 * @throws OutOfBoundsException If index is out of bounds (index < 0 || index > count)
	 * @param int $index
	 * @param Traversable $elements
	 * @return void
	 */
	public function addAllByIndex($index, $elements);
	
	/**
	 * Returns the element at a given index (if set)
	 * 
	 * @throws OutOfBoundsException If index is out of bounds (index < 0 || index >= count)
	 * @param int $index
	 * @return mixed|null Returns null if index is not set
	 */
	public function get($index);
	
	/**
	 * Returns true if an element is set at a given index
	 * 
	 * @param int $index
	 * @return bool
	 */
	public function has($index);
	
	/**
	 * Returns the first index for a given element (if any)
	 * 
	 * @param mixed $element
	 * @return int|null Returns null if element not in list
	 */
	public function indexOf($element);
	
	/**
	 * Returns all indices for a given element (if any)
	 * 
	 * @param mixed $element
	 * @return int[]
	 */
	public function indicesOf($element);
	
	/**
	 * Removes an element from the list by its index
	 * 
	 * @throws OutOfBoundsException If index is out of bounds (index < 0 || index >= count)
	 * @param int $index
	 * @return void
	 */
	public function removeByIndex($index);
	
	/**
	 * Removes any elements in the given index range
	 * 
	 * @throws OutOfBoundsException If fromIndex is out of bounds (index < 0 || index >= count)
	 * @throws OutOfBoundsException If toIndex is out of bounds (index < 0 || index >= count)
	 * @throws OutOfBoundsException If toIndex is less than fromIndex
	 * @param int $fromIndex
	 * @param int $toIndex
	 * @return void
	 */
	public function removeByIndexRange($fromIndex, $toIndex);
	
	/**
	 * Sets an index to a given element
	 * 
	 * @throws OutOfBoundsException If index is out of bounds (index < 0 || index >= count)
	 * @param int $index
	 * @param mixed $element
	 * @return void
	 */
	public function set($index, $element);
}